﻿<%@ Page Title="Report Creation" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="ReportCreation.aspx.cs" Inherits="TestJQGrid.ReportCreation" %>

<%@ Register Assembly="Trirand.Web" Namespace="Trirand.Web.UI.WebControls" TagPrefix="trirand" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <!-- The jQuery UI theme that will be used by the grid -->
    <link rel="stylesheet" type="text/css" media="screen" href="../../themes/redmond/jquery-ui-1.8.2.custom.css" />
    <!-- The jQuery UI theme extension jqGrid needs -->
    <link rel="stylesheet" type="text/css" media="screen" href="../../themes/ui.jqgrid.css" />
    <!-- jQuery runtime minified -->
    <script src="../../js/jquery-1.4.4.min.js" type="text/javascript"></script>
    <!-- The localization file we need, English in this case -->
    <script src="../../js/trirand/i18n/grid.locale-en.js" type="text/javascript"></script>
    <!-- The jqGrid client-side javascript -->
    <script src="../../js/trirand/jquery.jqGrid.min.js" type="text/javascript"></script>
    <script src="../../js/trirand/jquery.jqDatePicker.min.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table border="1px">
        <tr>
            <td rowspan="4" style="width: 20%;" align="left" valign="top">
                <asp:ListBox ID="LBReports" runat="server" DataSourceID="SqlDataSource1" DataTextField="ReportName"
                    DataValueField="ReportId" Rows="25" Width="100%" OnDataBound="LBReports_DataBound"
                    OnSelectedIndexChanged="LBReports_SelectedIndexChanged" AutoPostBack="True">
                </asp:ListBox>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AgentBillingConnectionString %>"
                    SelectCommand="SELECT [ReportId], [ReportName] FROM [Reports] WHERE ([ProductName] = @ProductName)">
                    <SelectParameters>
                        <asp:SessionParameter DefaultValue="CarSales" Name="ProductName" SessionField="ProductName"
                            Type="String" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </td>
            <td align="center" style="height: 8%;" valign="middle">
                <asp:Label ID="LabelName" runat="server" Text="Report Name" Width="100px"></asp:Label>
                <asp:TextBox ID="TBName" runat="server" Width="200px" EnableViewState="False"></asp:TextBox>
                <asp:Label ID="Label1" runat="server" Width="50px"></asp:Label>
                <asp:Label ID="Label2" runat="server" Text="Type" Width="50px"></asp:Label>
                <asp:DropDownList ID="DDLPPType" runat="server">
                    <asp:ListItem>Public</asp:ListItem>
                    <asp:ListItem>Private</asp:ListItem>
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td align="left" style="height: 74%; width: 80%;" valign="top">
                <trirand:JQGrid runat="server" ID="JQGrid1" Height="300px" Width="700px" OnRowAdding="JQGrid1_RowAdding"
                    OnRowDeleting="JQGrid1_RowDeleting" OnRowEditing="JQGrid1_RowEditing">
                    <Columns>
                        <trirand:JQGridColumn DataField="FieldId" HeaderText="No" Visible="false" PrimaryKey="True" />
                        <trirand:JQGridColumn DataField="DisplayType" Editable="true" EditType="DropDown"
                            EditorControlID="DDLType" />
                        <trirand:JQGridColumn DataField="Field" Editable="true" EditType="DropDown" EditorControlID="DDLFields" />
                        <trirand:JQGridColumn DataField="DisplayName" Editable="true" />
                        <trirand:JQGridColumn DataField="Operator" Editable="true" EditType="DropDown" EditorControlID="DDLOper" />
                        <trirand:JQGridColumn DataField="Value" Editable="true" />
                        <trirand:JQGridColumn DataField="DispAggr" HeaderText="SELECT Aggr" Editable="true"
                            EditType="DropDown" EditorControlID="DDLSelectAggr" />
                        <trirand:JQGridColumn DataField="FiltAggr" Editable="false" Visible="false" EditType="DropDown"
                            EditorControlID="DDLHavingAggr" />
                        <trirand:JQGridColumn DataField="FiltOperator" Editable="false" Visible="false" EditType="DropDown"
                            EditorControlID="DDLHavingOper" />
                        <trirand:JQGridColumn DataField="FiltValue" Editable="false" Visible="false" />
                    </Columns>
                    <ToolBarSettings ShowAddButton="true" ShowEditButton="true" ShowDeleteButton="true"
                        ShowRefreshButton="True" ShowSearchButton="True" ShowViewRowDetailsButton="True" />
                    <EditDialogSettings CloseAfterEditing="True" />
                    <AddDialogSettings CloseAfterAdding="True" />
                    <SearchDialogSettings MultipleSearch="true" />
                    <SortSettings InitialSortColumn=""></SortSettings>
                </trirand:JQGrid>
                <asp:DropDownList ID="DDLType" runat="server" Visible="false">
                    <asp:ListItem Value="SELECT" Text="SELECT" Selected="True"></asp:ListItem>
                    <asp:ListItem Value="WHERE" Text="WHERE"></asp:ListItem>
                    <asp:ListItem Value="GROUP BY" Text="GROUP BY"></asp:ListItem>
                </asp:DropDownList>
                <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:AgentBillingConnectionString %>  "
                    DeleteCommand="DELETE FROM [ReportFields] WHERE [ReportId] = @ReportId AND [FieldId] = @FieldId"
                    InsertCommand="INSERT INTO [ReportFields] ([ReportId], [FieldId], [DisplayType], [Field], [Operator], [Value], [DispAggr], [FiltAggr], [FiltOperator], [FiltValue]) VALUES (@ReportId, @FieldId, @DisplayType, @Field, @Operator, @Value, @DispAggr, @FiltAggr, @FiltOperator, @FiltValue)"
                    SelectCommand="SELECT [FieldId], [DisplayType], [Field], [Operator], [Value], [DispAggr], [FiltAggr], [FiltOperator], [FiltValue] FROM [ReportFields] WHERE ([ReportId] = @ReportId)"
                    UpdateCommand="UPDATE [ReportFields] SET [DisplayType] = @DisplayType, [Field] = @Field, [Operator] = @Operator, [Value] = @Value, [DispAggr] = @DispAggr, [FiltAggr] = @FiltAggr, [FiltOperator] = @FiltOperator, [FiltValue] = @FiltValue WHERE [ReportId] = @ReportId AND [FieldId] = @FieldId">
                    <DeleteParameters>
                        <asp:Parameter Name="ReportId" Type="Decimal" />
                        <asp:Parameter Name="FieldId" Type="Decimal" />
                    </DeleteParameters>
                    <InsertParameters>
                        <asp:Parameter Name="ReportId" Type="Decimal" />
                        <asp:Parameter Name="FieldId" Type="Decimal" />
                        <asp:Parameter Name="DisplayType" Type="String" />
                        <asp:Parameter Name="Field" Type="String" />
                        <asp:Parameter Name="Operator" Type="String" />
                        <asp:Parameter Name="Value" Type="String" />
                        <asp:Parameter Name="DispAggr" Type="String" />
                        <asp:Parameter Name="FiltAggr" Type="String" />
                        <asp:Parameter Name="FiltOperator" Type="String" />
                        <asp:Parameter Name="FiltValue" Type="String" />
                    </InsertParameters>
                    <SelectParameters>
                        <asp:ControlParameter ControlID="LBReports" Name="ReportId" PropertyName="SelectedValue"
                            Type="Decimal" />
                    </SelectParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="DisplayType" Type="String" />
                        <asp:Parameter Name="Field" Type="String" />
                        <asp:Parameter Name="Operator" Type="String" />
                        <asp:Parameter Name="Value" Type="String" />
                        <asp:Parameter Name="DispAggr" Type="String" />
                        <asp:Parameter Name="FiltAggr" Type="String" />
                        <asp:Parameter Name="FiltOperator" Type="String" />
                        <asp:Parameter Name="FiltValue" Type="String" />
                        <asp:Parameter Name="ReportId" Type="Decimal" />
                        <asp:Parameter Name="FieldId" Type="Decimal" />
                    </UpdateParameters>
                </asp:SqlDataSource>
                <asp:DropDownList ID="DDLOper" runat="server">
                    <asp:ListItem Selected="True" Text="" Value=""></asp:ListItem>
                    <asp:ListItem>=</asp:ListItem>
                    <asp:ListItem Value="<">&lt;&lt;</asp:ListItem>
                    <asp:ListItem>&gt;</asp:ListItem>
                    <asp:ListItem>&lt;=</asp:ListItem>
                    <asp:ListItem>&gt;=</asp:ListItem>
                    <asp:ListItem>!=</asp:ListItem>
                    <asp:ListItem>LIKE</asp:ListItem>
                    <asp:ListItem>NOT LIKE</asp:ListItem>
                    <asp:ListItem>CONTAINS</asp:ListItem>
                </asp:DropDownList>
                <asp:DropDownList ID="DDLHavingOper" runat="server" Visible="false">
                    <asp:ListItem Selected="True" Text="" Value=""></asp:ListItem>
                    <asp:ListItem>=</asp:ListItem>
                    <asp:ListItem Value="<">&lt;&lt;</asp:ListItem>
                    <asp:ListItem>&gt;</asp:ListItem>
                    <asp:ListItem>&lt;=</asp:ListItem>
                    <asp:ListItem>&gt;=</asp:ListItem>
                    <asp:ListItem>!=</asp:ListItem>
                    <asp:ListItem>LIKE</asp:ListItem>
                    <asp:ListItem>NOT LIKE</asp:ListItem>
                    <asp:ListItem>CONTAINS</asp:ListItem>
                </asp:DropDownList>
                <asp:DropDownList ID="DDLSelectAggr" runat="server">
                    <asp:ListItem Selected="True" Text="" Value=""></asp:ListItem>
                    <asp:ListItem>SUM</asp:ListItem>
                    <asp:ListItem>AVG</asp:ListItem>
                    <asp:ListItem>MIN</asp:ListItem>
                    <asp:ListItem>MAX</asp:ListItem>
                    <asp:ListItem>COUNT</asp:ListItem>
                </asp:DropDownList>
                <asp:DropDownList ID="DDLHavingAggr" runat="server" Visible="false">
                    <asp:ListItem Selected="True" Text="" Value=""></asp:ListItem>
                    <asp:ListItem>SUM</asp:ListItem>
                    <asp:ListItem>AVG</asp:ListItem>
                    <asp:ListItem>MIN</asp:ListItem>
                    <asp:ListItem>MAX</asp:ListItem>
                    <asp:ListItem>COUNT</asp:ListItem>
                </asp:DropDownList>
                <asp:DropDownList ID="DDLFields" runat="server" DataSourceID="SqlDataSource3" DataTextField="ColumnsList"
                    DataValueField="ColumnsList">
                </asp:DropDownList>
                <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:AgentBillingConnectionString %>"
                    SelectCommand="select (cp.TableName + '.' + cp.ColumnName) AS ColumnsList from ColumnProperties cp where cp.TableName in ( select tr.RelatedTable from TableRelation tr, ProductList pl where pl.ProductName = @ProductName AND pl.TableName = tr.PrimaryTable ) OR cp.TableName in ( select pl.TableName from ProductList pl where pl.ProductName = @ProductName ) AND cp.ColumnName not in ('EntryStatus','Product','ProductName') Order By ColumnsList">
                    <SelectParameters>
                        <asp:SessionParameter DefaultValue="CarSales" Name="ProductName" Type="String" SessionField="ProductName" />
                    </SelectParameters>
                </asp:SqlDataSource>
                <asp:DropDownList ID="DDLFormula" runat="server" DataSourceID="SqlDataSource4" DataTextField="FormulaName"
                    DataValueField="FormulaName" Visible="false">
                </asp:DropDownList>
                <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:AgentBillingConnectionString %>"
                    SelectCommand="SELECT [FormulaName] FROM [FormulaTable] WHERE ([FormulaType] = @FormulaType) AND ([SubType] = @SubType)">
                    <SelectParameters>
                        <asp:Parameter DefaultValue="Formula" Name="FormulaType" Type="String" />
                        <asp:Parameter DefaultValue="Report Creation" Name="SubType" Type="String" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </td>
        </tr>
        <tr align="center" valign="middle" style="height: 8%;">
            <td>
                <asp:Label ID="LabelEmail" runat="server" Text="EMail ID : "></asp:Label>
                <asp:TextBox ID="TBEmail" runat="server" Height="16px" Width="350px"></asp:TextBox>
                <asp:RegularExpressionValidator ID="EmailValidator" runat="server" ControlToValidate="TBEmail"
                    ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
                </asp:RegularExpressionValidator>
                <asp:Label ID="Label3" runat="server" Text="Frequency" Width="80px"></asp:Label>
                <asp:DropDownList ID="DDLFrequency" runat="server">
                    <asp:ListItem>Daily</asp:ListItem>
                    <asp:ListItem>Weekly</asp:ListItem>
                    <asp:ListItem>Monthly</asp:ListItem>
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td align="center" style="height: 10%;" valign="middle">
                <asp:Button ID="BApply" runat="server" Text="Apply" Width="100px" OnClick="BApply_Click" />
                &nbsp;<asp:Button ID="BCancel" runat="server" Text="Cancel" Width="100px" OnClick="BCancel_Click" />
                &nbsp;<asp:Button ID="BEdit" runat="server" Text="Edit" Width="100px" OnClick="BEdit_Click" />
                &nbsp;<asp:Button ID="BCreate" runat="server" Text="Create New" Width="100px" OnClick="BCreate_Click" />
            </td>
        </tr>
    </table>
</asp:Content>
